import {
  mapGetters
} from 'vuex'
export default {
  computed: {
    ...mapGetters('cart', ['total'])
  },
  onShow() {
    uni.setTabBarBadge({
      index: 2,
      text: this.total + ''
    })
  },
  watch: {
    "total": {
      handler(newVal) {
        // #ifdef MP-WEIXIN 
        let pages = getCurrentPages() //获取加载的页面
        let currentPage = pages[pages.length - 1] //获取当前页面的对象
        let url = currentPage.route //当前页面url
        const tabbarList = ['pages/home/home', 'pages/cate/cate', 'pages/cart/cart', 'pages/my/my']
        if (tabbarList.includes(url)) {
          uni.setTabBarBadge({
            index: 2,
            text: newVal + ''
          })
        }
        // #endif

        // #ifdef  WEB
        uni.setTabBarBadge({
          index: 2,
          text: newVal + ''
        })
        // #endif

      },
      immediate: true
    }
  },
}